package com.chinatelecom.otms.circuitcheck.util;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Common<T> {

    public static String TABLE_NAME;
    public static CountDownLatch countDownLatch;
    public static ExecutorService singleThreadExecutor = Executors.newFixedThreadPool(10);

    public Map<String, List<T>> classifyListByStringParams(List<T> list, String params) throws NoSuchFieldException, IllegalAccessException {
        Map<String, List<T>> resultMap = new HashMap<>();
        for(T t : list){
            Field field = t.getClass().getDeclaredField(params);
            field.setAccessible(true);
            Object o = field.get(t);
            String key = String.valueOf(o);
            if(resultMap.keySet().contains(key)){
                resultMap.get(key).add(t);
            }else{
                List<T> tempList = new ArrayList<>();
                tempList.add(t);
                resultMap.put(key, tempList);
            }
        }
        return resultMap;
    }
}
